export default {
  TopLoadingStart() {
    let loadingBar = document.getElementById('global-loading')
    if (!loadingBar) {
      loadingBar = document.createElement('div')
      loadingBar.id = 'global-loading'
      document.body.append(loadingBar)
    } else {
      loadingBar.style.display = 'block'
    }
  },
  TopLoadingFinish() {
    let loadingBar = document.getElementById('global-loading')
    if (loadingBar) {
      loadingBar.style.display = 'none'
    }
  },
  WebTitleIcon() {
    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
    link.type = 'image/x-icon';
    link.rel = 'shortcut icon';
    link.href = 'http://www.stackoverflow.com/favicon.ico';
    document.getElementsByTagName('head')[0].appendChild(link);
  },
  getRandomStr(length) {
    length = length || 32
    let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678' /** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    let maxPos = $chars.length
    let Str = ''
    for (var i = 0; i < length; i++) {
      Str += $chars.charAt(Math.floor(Math.random() * maxPos))
    }
    let time = new Date().getTime().toString()
    return Str + time.substring(4,time.length)
  }
}
